package logic

import (
	"context"
	"user_srv/user"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SendSmsLogic) SendSms(req *types.SendSmsrequest) (resp *types.Response, err error) {
	sms, err := l.svcCtx.Userrpc.SendSms(l.ctx, &user.SendSmsRequest{
		Mobile: req.Mobile,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: "短信验证码发送失败",
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Code:    500,
		Message: "短信验证码发送成功",
		Data:    sms,
	}, nil
}
